package gridView;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Paint;
import java.awt.RenderingHints;

import javax.swing.JPanel;

public class GradientPanel extends JPanel {
	
	// ATTRIBUTS
	
	public static final int VERTICAL = 0;
	public static final int HORIZONTAL = 1;
	
	private static final long serialVersionUID = 1L;
	
	private final int axe;
	private final Color color1;
	private final Color color2;
	
	// CONSTRUCTEUR
	
	public GradientPanel(int axe, Color color1, Color color2) {
		this(axe, color1, color2, new FlowLayout());
	}
	
	public GradientPanel(int axe, Color color1, Color color2, LayoutManager lm) {
		super(lm);
		this.axe = axe;
		this.color1 = color1;
		this.color2 = color2;
	}
	
	// COMMANDES

	public void paintComponent(Graphics _g) {
		Graphics2D g = (Graphics2D) _g;
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
		        RenderingHints.VALUE_ANTIALIAS_ON);
		Paint gradientPaint = null;
		switch (axe) {
		case VERTICAL: gradientPaint = new GradientPaint(0, getHeight(), color1, 0, getWidth(), color2);
		break;
		case HORIZONTAL: gradientPaint = new GradientPaint(0, 0, color2, getWidth(), getHeight(), color1);
		break;
		}
		g.setPaint(gradientPaint);
		g.fillRect(0, 0, getWidth(), getHeight());
	}
	
}
